/* Copyright (c) 2021, National University of Defense Technology. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PARCSR_ILU_PRECONDITIONER_H
#define PARCSR_ILU_PRECONDITIONER_H

#include "parcsr_preconditioner.h"

namespace YHAMG
{

class ParCSR_ILU_Preconditioner : public ParCSR_Preconditioner
{
private:
	Vector D_Recip_Loc;
	CSR_Matrix L_LocLoc;
	CSR_Matrix L_LocExt;
	CSR_Matrix U_LocLoc;
	CSR_Matrix U_LocExt;
	Vector x_Ext;

	bool* interior;

	int label;
	int num_neighbors;
	int* neighbor_labels;
	int* neighbor_ranks;

	int* recv_ptr;
	int* send_ptr;
	int* send_list;
	double* send_buffer;

public:
	ParCSR_ILU_Preconditioner();
	~ParCSR_ILU_Preconditioner();
	
	void Free();
	void Setup(const ParCSR_Matrix& A, int REUSE = 0);
	int InSize() const;
	int OutSize() const;
	void Apply(const Par_Vector& b, const Par_Vector& x) const;
};

}

#endif